/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('layoutadmin', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model UserRelation {
  businessId?: string(name='BusinessId'),
  gmtCreated?: string(name='GmtCreated'),
  relationId?: string(name='RelationId'),
  userId?: string(name='UserId'),
}

model AddRelationRequest {
  businessId?: string(name='BusinessId'),
  userId?: string(name='UserId'),
}

model AddRelationResponseBody = {
  code?: string(name='Code'),
  dynamicMessage?: string(name='DynamicMessage'),
  message?: string(name='Message'),
  relationId?: string(name='RelationId'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model AddRelationResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: AddRelationResponseBody(name='body'),
}

async function addRelationWithOptions(request: AddRelationRequest, runtime: Util.RuntimeOptions): AddRelationResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.businessId)) {
    query['BusinessId'] = request.businessId;
  }
  if (!Util.isUnset(request.userId)) {
    query['UserId'] = request.userId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'AddRelation',
    version = '2022-08-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function addRelation(request: AddRelationRequest): AddRelationResponse {
  var runtime = new Util.RuntimeOptions{};
  return addRelationWithOptions(request, runtime);
}

model DeleteRelationRequest {
  relationId?: string(name='RelationId'),
}

model DeleteRelationResponseBody = {
  code?: string(name='Code'),
  dynamicMessage?: string(name='DynamicMessage'),
  message?: string(name='Message'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
}

model DeleteRelationResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: DeleteRelationResponseBody(name='body'),
}

async function deleteRelationWithOptions(request: DeleteRelationRequest, runtime: Util.RuntimeOptions): DeleteRelationResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.relationId)) {
    query['RelationId'] = request.relationId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'DeleteRelation',
    version = '2022-08-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function deleteRelation(request: DeleteRelationRequest): DeleteRelationResponse {
  var runtime = new Util.RuntimeOptions{};
  return deleteRelationWithOptions(request, runtime);
}

model QueryRelationRequest {
  businessId?: string(name='BusinessId'),
  pageNumber?: long(name='PageNumber'),
  pageSize?: long(name='PageSize'),
  relationId?: string(name='RelationId'),
  userId?: string(name='UserId'),
}

model QueryRelationResponseBody = {
  code?: string(name='Code'),
  dynamicMessage?: string(name='DynamicMessage'),
  message?: string(name='Message'),
  pageNumber?: long(name='PageNumber'),
  pageSize?: long(name='PageSize'),
  relations?: [
    UserRelation
  ](name='Relations'),
  requestId?: string(name='RequestId'),
  success?: boolean(name='Success'),
  totalCount?: long(name='TotalCount'),
}

model QueryRelationResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: QueryRelationResponseBody(name='body'),
}

async function queryRelationWithOptions(request: QueryRelationRequest, runtime: Util.RuntimeOptions): QueryRelationResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.businessId)) {
    query['BusinessId'] = request.businessId;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.relationId)) {
    query['RelationId'] = request.relationId;
  }
  if (!Util.isUnset(request.userId)) {
    query['UserId'] = request.userId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryRelation',
    version = '2022-08-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function queryRelation(request: QueryRelationRequest): QueryRelationResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryRelationWithOptions(request, runtime);
}

